home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Internet Info 1994 March
/
Internet Info CD-ROM (Walnut Creek) (March 1994).iso
/
networking
/
ip
/
ka9q
/
xobbs.arc
/
xouser.c
< prev
Wrap
C/C++ Source or Header
|
1989-05-03
|
5KB
|
163 lines
/* XOUSER.C User database routines for XOBBS. Jim Durham, W2XO 10-24-88 */
/* Version 1.0 */
/* Code released to the amateur radio community */
#include "xobbs.h"
edituser(call)
char *call;
{
int fd;
struct userrecord usrrec;
int highest,recnum,fail;
upcase(call); /*convert the call to upper case*/
if((fd=open(userfil,O_RDWR)) < 0) /*try to open the user file*/
{
perror("edituser:Cant open user file");
sndupkil();
}
fail=1;
getrec(fd,0,&usrrec,sizeof(usrrec));
highest=usrrec.highest;
for(recnum=1;recnum <= highest;recnum++){
getrec(fd,recnum,&usrrec,sizeof(usrrec));
if(!strcmp(call,usrrec.call)){
fail=0;
break;
}
}
if(fail){
sprintf(prinbuf,"***No such user*** \n");
prinout(NOFLUSH);
return 1;
}
for(;;){
sprintf(prinbuf,"Call: %s\n",usrrec.call);
prinout(NOFLUSH);
sprintf(prinbuf,"Name: %s\n",usrrec.name);
prinout(NOFLUSH);
sprintf(prinbuf,"Type: %c\n\n",usrrec.type);
prinout(NOFLUSH);
sprintf(prinbuf,"CR to Quit, C to change call, N to change name, T to change Type\n");
prinout(FLUSH);
getline(0);
switch(inline[0]){
case 'C':
case 'c': sprintf(prinbuf,"New Call?:");
prinout(FLUSH);
getline(0);
stringcpy(usrrec.call,inline,6);
break;
case 'N':
case 'n': sprintf(prinbuf,"New Name?:");
prinout(FLUSH);
getline(0);
stringcpy(usrrec.name,inline,20);
break;
case 'T':
case 't': sprintf(prinbuf,"New Type?:");
prinout(FLUSH);
getline(0);
usrrec.type=inline[0];
break;
default: lseek(fd,(long)(-sizeof(usrrec)),1);
putrec(fd,recnum,&usrrec,sizeof(usrrec));
close(fd);
return 0;
}
}
}
getuser(call)
char *call;
{
int fd;
struct userrecord usrrec;
int highest,recnum,fail;
upcase(call); /*convert the call to upper case*/
if((fd=open(userfil,O_RDWR|O_CREAT,0x1b6)) < 0)/*try to open the user file*/
{
perror("getuser:Can't open User File");
sndupkil();
}
fail=1;
getrec(fd,0,&usrrec,sizeof(usrrec));
if(strcmp(usrrec.call,"******")){ /*if file never initialized*/
strcpy(usrrec.call,"******");
usrrec.highest=highest=0;
putrec(fd,0,&usrrec,sizeof(usrrec)); /*initialize file*/
}
highest=usrrec.highest;
for(recnum=1;recnum <= highest;recnum++){
getrec(fd,recnum,&usrrec,sizeof(usrrec));
if(!strcmp(call,usrrec.call)){
fail=0;
break;
}
}
if(fail){
strcpy(usrrec.name,"NO_NAME"); /* we dont know his name*/
strcpy(user.call,call); /* copy call to user.call*/
strcpy(usrrec.call,call);
usrrec.highest=0;
usrrec.type='N'; /*assume novice user*/
gettim();
sprintf(usrrec.dat,"%02d%02d%02d\0",newtime->tm_year,newtime->tm_mon,newtime->tm_mday);
putrec(fd,highest+1,&usrrec,sizeof(usrrec));
getrec(fd,0,&usrrec,sizeof(usrrec));
usrrec.highest=highest+1;
putrec(fd,0,&usrrec,sizeof(usrrec));
sprintf(prinbuf,"Please use N command to enter name <N Name>\n\n");
prinout(NOFLUSH);
}
else{ /*we DO know this guy*/
strcpy(user.call,usrrec.call); /*put the call into user data area*/
user.highest=usrrec.highest; /* and write it to user*/
strcpy(user.name,usrrec.name); /* and write it to user*/
user.typ=usrrec.type;
gettim();
sprintf(usrrec.dat,"%02d%02d%02d\0",newtime->tm_year,newtime->tm_mon,newtime->tm_mday);
usrrec.highest=highnum;
lseek(fd,(long)(-sizeof(usrrec)),1);
putrec(fd,recnum,&usrrec,sizeof(usrrec)); /*write updated record*/
}
close(fd);
}
doname(nam)
char *nam;
{
int fd,recnum,highest;
struct userrecord usrrec;
upcase(nam);
if((fd=open(userfil,O_RDWR)) < 0) /*try to open the user file*/
{
sprintf(prinbuf,"Can't open %s\n",userfil);
perror(prinbuf);
sndupkil();
}
getrec(fd,0,&usrrec,sizeof(usrrec));
highest=usrrec.highest;
for(recnum=1;recnum <= highest;recnum++){
getrec(fd,recnum,&usrrec,sizeof(usrrec));
if(!strcmp(usrrec.call,user.call)){
strcpy(usrrec.name,nam);
strcpy(user.name,nam);
putrec(fd,recnum,&usrrec,sizeof(usrrec));
break;
}
}
close(fd); /*close the user file*/
}